<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * token检测
 * @author  :  Calvin <dev@skiy.net>
 */

class Token{

    public function __construct() {
        $this->ci = &get_instance();
        if(!$this->ci)RETURN TRUE;
        $this->ci->load->service("token_service");
    }

    public function token_check() {
        if(!$this->ci)RETURN TRUE;
        $method = strtolower($this->ci->input->server('REQUEST_METHOD'));
        if($method=="options"){
            Common::ajax_return(0);
        }
        //$uri = $this->get_url();
        $dir = str_replace("/","",$this->ci->router->directory);
        //$get_key = config_item("rest_access_token_get_key");
        //$token = htmlspecialchars($_REQUEST[$get_key],ENT_QUOTES);
        $token = $this->ci->input->get("_token");
        if(!empty($token) && empty($dir) ) {
            return $this->ci->token_service->token_valid();
        }
        return TRUE;
    }

}